package nancal.mp.extend

import nancal.mp.db.mongo.ISysDict
import nbcp.base.comm.MemoryCacheList
import nbcp.base.comm.config
import nbcp.base.extend.AsString
import nbcp.myoql.db.db
import nbcp.myoql.db.mongo.entity.SysDictionary
import nbcp.myoql.db.mongo.query
import java.time.LocalDateTime
import java.time.ZoneId

fun ISysDict.getDictValue(): String {
    return (MemoryCacheList.expireAfterWrite4Hours.get("sys_dict") {
        return@get db.morBase.sysDictionary
                .query()
                .where { it.group mongoEquals config.appGroup }
                .toList()
    } as List<SysDictionary>)
            .firstOrNull { it.key == this.key }
            ?.value
            .AsString()
}



fun LocalDateTime.toBjTime(): LocalDateTime {
    return this.atZone(ZoneId.systemDefault()).withZoneSameInstant(ZoneId.of("Asia/Shanghai")).toLocalDateTime()
}

